function add() {
	$.ajax({
		type : "post",
		url : appPath + "/address/add.html",
		dataType : "html",
		data : {
			token : $.cookie("token")
		},
		success : function(result) {
			if(result.indexOf("loginpage") > -1){
				location.href = appPath + "/member/login.html";
			}
			$("body").html(result);
			$("#area").cityPicker({
				title : "选择地区"
			});
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
            $.alert("系统异常，请稍后再试");
        }
	});
}

function del(addressid) {
	$.confirm("确定要删除吗？", function() {
		$.showLoading();
		$.ajax({
			type : "post",
			url : appPath + "/address/del.html",
			data : {
				addressid : addressid,
				token : $.cookie("token")
			},
			success : function(result) {
				$.hideLoading();
				$.alert(result.msg, function() {
					if (result.code == '1') {
						location.reload();
					} else if (result.code == -1){
						window.location = appPath + "/member/login.html";
					}
				});
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$.hideLoading();
	            $.alert("系统异常，请稍后再试");
	        }
		});
	})
}

function edit(addressid) {
 	$.ajax({
		type : "post",
		url : appPath + "/address/edit.html",
		dataType : "html",
		data : {
			addressid : addressid,
			token : $.cookie("token")
		},
		success : function(result) {
			if(result.indexOf("loginpage") > -1){
				location.href = appPath + "/member/login.html";
			}
			$("body").html(result);
			$("#area").cityPicker({
				title : "选择地区"
			});
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
            $.alert("系统异常，请稍后再试");
        }
	});
}

function setDefault(addressid){
	$.showLoading();
	$.ajax({
		type : "post",
		url : appPath + "/address/setDefault.html",
		data : {
			addressid : addressid,
			token : $.cookie("token")
		},
		success : function(result) {
			$.hideLoading();
			$.alert(result.msg, function() {
				if (result.code == '1') {
					location.reload();
				} else if (result.code == -1){
					window.location = appPath + "/member/login.html";
				}
			});
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			$.hideLoading();
            $.alert("系统异常，请稍后再试");
        }
	});
}

function chooseOver(obj){
	gotoHtml("/order/preOrderInfo.html?addressId=" + obj.id + "&singleBuyFlag=" + $("#singleBuyFlag").val());
}